var pageSize = 10;
var pageNum = 1;
var page;
var laypage;
var list;
var layer;


$(function () {
    $("#menuId").val(sessionStorage.menuId);
    var menuId = $("#menuId").val();
    if(sessionStorage.getItem(menuId+'add') == 1){
        $("#addAgent").css('display','inline');
    }
    // alert("000"+sessionStorage.menuId);
    layui.use(['laydate', 'element', 'laypage', 'layer'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        element = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层

        //以上模块根据需要引入

        var start = {
            // min: laydate.now(),
            max: '2099-06-16 23:59:59'
            ,istoday: true
            ,choose: function(datas){
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };

        var end = {
            // min: laydate.now(),
            max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };



        document.getElementById('LAY_demorange_s').onclick = function(){
            start.elem = this;
            laydate(start);
        }
        document.getElementById('LAY_demorange_e').onclick = function(){
            end.elem = this
            laydate(end);
        }

    });
    setTimeout(function () {
        findAgentList();
        // findAllProvince();
    }, 200);

});


//查询代理商列表
function findAgentList() {
    var menuId = $("#menuId").val();
    // var provinceCode = $("#province").val();
    // var cityCode = $("#city").val();
    // var countyCode = $("#area").val();
    var startTime = $("#LAY_demorange_s").val();
    var endTime = $("#LAY_demorange_e").val();
    var phone = $("#phone").val();

    var params = {
        "type": "query",
        "menuId": menuId,
        "pageSize": pageSize,
        "pageNum": pageNum,
        "phone":phone,
        "startTime":startTime,
        "endTime":endTime
    };
    $.ajax({
        type: "post",
        url: "/agent/findAgentList",
        data: params,
        dataType: "json",
        success: function (data) {
            if (data.code == 1 && data.code != undefined) {
                list = data.agents;
                page = data.page;
                var html = "";
                for (var b in list) {
                    var stateStr = "";
                    if (list[b].state == 1) {
                        stateStr = "正常";
                    } else if (list[b].state == 2) {
                        stateStr = "已锁定";
                    }
                    var agentLevelStr = "";
                    if (list[b].agentLevel == 1) {
                        agentLevelStr = "区县代理";
                    }else if(list[b].agentLevel == 2){
                        agentLevelStr = "市级代理";
                    }else if(list[b].agentLevel == 3){
                        agentLevelStr = "省级代理";
                    }
                    html += '<tr><td>' + list[b].phone + '</td>' +
                        '<td>' + list[b].nickName + '</td>' +
                        '<td>' + agentLevelStr + '</td>' +
                        '<td>' + (list[b].provinceCode == null ? "" : list[b].provinceCode) + '</td>' +
                        '<td>' + (list[b].cityCode == null ? "" : list[b].cityCode) + '</td>' +
                        '<td>' + (list[b].countyCode == null ? "" : list[b].countyCode) + '</td>' +
                        '<td>' + new Date(list[b].signingDate).toLocaleString() + '</td>' +
                        '<td>' + new Date(list[b].createTime).toLocaleString() + '</td>' +
                        '<td>' + stateStr + '</td>' +
                        '<td></td></tr>';
                }
                $("#bus").html(html);
                $("#total").html("共有数据：" + page.total + " 条");
                laypage({
                    cont: 'page'
                    , pages: page.pages
                    , first: 1
                    , curr: pageNum
                    , last: page.pages
                    , prev: '<em><</em>'
                    , next: '<em>></em>'
                    , jump: function (obj, first) {
                        pageNum = obj.curr;
                        if (!first) {
                            findAgentList();
                        }
                    }
                });
            } else if (data == 9999 && data != undefined) {
                window.location.href = "/login_toLogin";
            } else if (data == 1111 && data != undefined) {
                alert("无权操作");
            }else if(data.code == 2 && data.code != undefined){
                $("#bus").html("");
            }
        }

    });
}


//查询按钮
function search() {
    pageNum = 1;
    findAgentList();
}

//查询所有省份
function findAllProvince() {
    var menuId = $("#menuId").val();
    var params = {
        "type": "query",
        "menuId": menuId
    };
    $.ajax({
        type: "post",
        url: "/agent/findAllProvince",
        data: params,
        dataType: "json",
        success: function (data) {
            var html = "";
            if (data.code == 1 && data.code != undefined) {
                var hatProvinces = data.hatProvinces;
                for (var p in hatProvinces) {
                    html += '<option value="' + hatProvinces[p].provinceid + '">' + hatProvinces[p].province + '</option>'
                }
            } else if (data == 9999 && data != undefined) {
                window.location.href = "/login_toLogin";
            }
            $("#province").append(html);
        }
    });
}

//根据省份查询市
function findCityByProvince(provinceId) {
    if (provinceId != 0 && provinceId != undefined) {
        var menuId = $("#menuId").val();
        var params = {
            "type": "query",
            "menuId": menuId,
            "provinceId": provinceId
        };
        $.ajax({
            type: "post",
            url: "/agent/findCityByProvince",
            data: params,
            dataType: "json",
            success: function (data) {
                var html = ' <option value="">市(直辖市)</option>';
                if (data.code == 1 && data.code != undefined) {
                    var hatCities = data.hatCities;
                    for (var p in hatCities) {
                        html += '<option value="' + hatCities[p].cityid + '">' + hatCities[p].city + '</option>'
                    }
                } else if (data == 9999 && data != undefined) {
                    window.location.href = "/login_toLogin";
                } else if (data == 1111 && data != undefined) {
                    alert("无权操作");
                }
                $("#city").html(html);
            }
        });
    } else {
        $("#city").html(' <option value="">市(直辖市)</option>');
        $("#area").html('<option value="">区县</option>');
    }
}

//根据市查询区县
function findAreaByCity(cityId) {
    if (cityId != 0 && cityId != undefined) {
        var menuId = $("#menuId").val();
        var params = {
            "type": "query",
            "menuId": menuId,
            "cityId": cityId
        };
        $.ajax({
            type: "post",
            url: "/agent/findAreaByCity",
            data: params,
            dataType: "json",
            success: function (data) {
                var html = ' <option value="">区县</option>';
                if (data.code == 1 && data.code != undefined) {
                    var hatAreas = data.hatAreas;
                    for (var p in hatAreas) {
                        html += '<option value="' + hatAreas[p].areaid + '">' + hatAreas[p].area + '</option>'
                    }
                } else if (data == 9999 && data != undefined) {
                    window.location.href = "/login_toLogin";
                } else if (data == 1111 && data != undefined) {
                    alert("无权操作");
                }
                $("#area").html(html);
            }
        });
    } else {
        $("#area").html('<option value="">区县</option>');
    }
}

//添加代理商
var addAgentIndex;
function addAgent() {


    var addAgentHtml = '<table style="width: 80%;margin-top: 10px;margin-bottom:100px;border-collapse: separate;border-spacing: 10px"><tr><td style="width: 50%;"><strong style="float: right;">用户查询</strong></td><td style="width: 50%; float: left;"><input id="aPhone" onblur="findUser()" style="width: 89%;height: 30px" placeholder="请输入代理用户的手机号码"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">复核信息</strong></td><td style="width: 50%; float: left;"><input id="fPhone" disabled="disabled" style="width: 89%;height: 30px"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;"></strong></td><td style="width: 50%; float: left;"><input id="fName" disabled="disabled" style="width: 89%;height: 30px;"/><input id="fUserId" style="width: 89%;height: 30px;display: none"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">身份代理</strong></td><td style="width: 50%; float: left;"><select id="agentLevel"  style="width: 90%;height: 30px"><option value="1">区县代理</option><option value="2">市级代理</option><option value="3">省级代理</option></select></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">真实姓名</strong></td><td style="width: 50%; float: left;"><input id="agentName" style="width: 89%;height: 30px" placeholder="请输入真实姓名"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">身份证号码</strong></td><td style="width: 50%; float: left;"><input id="identityCard" style="width: 89%;height: 30px" placeholder="请输入身份证号码"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">代理区域</strong></td><td style="width: 50%; float: left;"><select id="provinceCode" onchange="findCity(this.value)" style="width: 30%;height: 30px"><option value="">请选择省份</option></select><select id="cityCode" onchange="findArea(this.value)" style="width: 30%;height: 30px;"><option value="">请选择市区</option></select><select id="countyCode" style="width: 30%;height: 30px"><option value="">请选择区县</option></select></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">是否推荐</strong></td><td style="width: 50%; float: left;"><input onclick="isParent(1)" type="radio" name="isParent" style="width: 40%;height: 30px;" checked="true" value="1"/>否<input onclick="isParent(2)" type="radio" name="isParent" style="width: 40%;height: 30px;" value="2"/>是</td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">推荐人</strong></td><td style="width: 50%; float: left;"><input id="parentPhone" style="width: 89%;height: 30px;" placeholder="请输入推荐人的手机号码" disabled="true"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">收益系数</strong></td><td style="width: 50%; float: left;"><input id="incomeCoefficient" style="width: 89%;height: 30px;" value="1"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">签约日期</strong></td><td style="width: 50%; float: left;"><input id="signingDate" readonly style="width: 89%;height: 30px;" placeholder="请选择签约日期"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">履约日期</strong></td><td style="width: 50%; float: left;"><input id="validStartDate" readonly style="width: 41%;height: 30px;"/>----<input id="validEndDate" readonly style="width: 41%;height: 30px;"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">经办人</strong></td><td style="width: 50%; float: left;"><input id="operatorName" style="width: 89%;height: 30px;" placeholder="请输入经办人姓名"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">合同号</strong></td><td style="width: 50%; float: left;"><input id="contractNo" style="width: 89%;height: 30px;" placeholder="请输入合同编号"/></td></tr>' +
        '<tr><td style="width: 50%;"><strong style="float: right;">上传身份证</strong></td><td style="width: 50%; float: left;"><div style="width: 700px;height: 200px;border: 1px solid">' +
        '<div style="width: 200px;display: inline-block;text-align: center;vertical-align: top;margin-left: 25px"><button onclick="zm.click()" class="layui-btn layui-btn-normal">上传身份证正面</button><input id="zm" name="myFile" style="display: none" type="file" onchange="preview(this,1)" /><div id="preview1" style="width: 200px;height: 100px;text-align: center;"></div></div>' +
        '<div style="width: 200px;display: inline-block;text-align: center;vertical-align: top;margin-left: 25px"><button onclick="fm.click()" class="layui-btn layui-btn-normal">上传身份证反面</button><input id="fm" name="myFile" style="display: none" type="file" onchange="preview(this,2)" /><div id="preview2" style="width: 200px;height: 100px;text-align: center;"></div></div>' +
        '<div style="width: 200px;display: inline-block;text-align: center;vertical-align: top;margin-left: 25px"><button onclick="sc.click()" class="layui-btn layui-btn-normal">上传手持身份证</button><input id="sc" name="myFile" style="display: none" type="file" onchange="preview(this,3)" /><div id="preview3" style="width: 200px;height: 100px;text-align: center;"></div></div>' +
        '</div></td></tr>' +
        '<tr><td style="width: 50%;"><button style="float: right;"class="layui-btn layui-btn-normal">取消保存</button></td><td style="width: 50%;text-align: center"><button class="layui-btn layui-btn-normal" onclick="addAgentSub(this)">确认保存</button></td></tr></table>';


    addAgentIndex = layer.open({
        title: ['添加代理商', 'color: #2299ee;border-bottom: 1px solid;']
        , type: 1
        , content: addAgentHtml
        , area: ['100%', '100%']
        , maxmin: true
    });

    var signingTime = {
        // min: laydate.now(),
        max: '2099-06-16 23:59:59'
        ,istoday: true
    };

    document.getElementById('signingDate').onclick = function(){
        signingTime.elem = this;
        laydate(signingTime);
    }

    var start = {
        // min: laydate.now(),
        max: '2099-06-16 23:59:59'
        ,istoday: true
        ,choose: function(datas){
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };

    var end = {
        min: laydate.now(),
        max: '2099-06-16 23:59:59'
        ,istoday: false
        ,choose: function(datas){
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };


    document.getElementById('validStartDate').onclick = function(){
        start.elem = this;
        laydate(start);
    }
    document.getElementById('validEndDate').onclick = function(){
        end.elem = this
        laydate(end);
    }

}

//图片预览
function preview(file, id) {
    var prevDiv = document.getElementById('preview' + id);
    var fileType = file.files[0].type;
    if(fileType != "image/pjpeg" && fileType != "image/jpeg" && fileType != "image/x-png" && fileType != "image/png"){
        alert("图片类型错误");
        return false;
    }
    if (file.files && file.files[0]) {
        var reader = new FileReader();
        reader.onload = function (evt) {
            prevDiv.innerHTML = '<img src="' + evt.target.result + '" style="width: 150px;height: 100px;"/>';
        }
        reader.readAsDataURL(file.files[0]);
    } else {
        prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
    }
}

//添加代理商
function addAgentSub(obj) {
    $(obj).attr("disabled",true);
    $(obj).attr("class","layui-btn layui-btn-disabled");
    var formData = new FormData();

    var fphone = $("#fPhone").val();
    if(fphone == "" || fphone == undefined){
        alert("请完善提交信息");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var provinceCode = ""; //省
    var cityCode = ""; //市
    var countyCode = ""; //区
    var agentLevel = $("#agentLevel").val(); //代理身份
    if(agentLevel == 3){
        provinceCode = $("#provinceCode").val();
        if(provinceCode == "" || provinceCode == undefined){
            alert("请完善提交信息");
            $(obj).attr("disabled",false);
            $(obj).attr("class","layui-btn layui-btn-normal");
            return false;
        }
    }else if(agentLevel == 2){
        provinceCode = $("#provinceCode").val();
        cityCode = $("#cityCode").val();
        if(provinceCode == "" || provinceCode == undefined || cityCode == "" || cityCode == undefined){
            alert("请完善提交信息");
            $(obj).attr("disabled",false);
            $(obj).attr("class","layui-btn layui-btn-normal");
            return false;
        }
    }else if(agentLevel == 1){
        provinceCode = $("#provinceCode").val();
        cityCode = $("#cityCode").val();
        countyCode = $("#countyCode").val();
        if(provinceCode == "" || provinceCode == undefined || cityCode == "" || cityCode == undefined || countyCode == "" || countyCode == undefined){
            alert("请完善提交信息");
            $(obj).attr("disabled",false);
            $(obj).attr("class","layui-btn layui-btn-normal");
            return false;
        }
    }
    var agentName = $("#agentName").val(); //真实姓名
    if(agentName == "" || agentName == undefined){
        alert("请完善提交信息");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var identityCard = $("#identityCard").val(); //身份证
    if(identityCard == "" || identityCard == undefined){
        alert("请完善提交信息");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var isParent = $("input[name=isParent]:checked").val();
    if(isParent == 2){
        var parentPhone = $("#parentPhone").val(); //推荐人
        if(parentPhone == "" || parentPhone == undefined){
            alert("请完善提交信息");
            $(obj).attr("disabled",false);
            $(obj).attr("class","layui-btn layui-btn-normal");
            return false;
        }
        if (!(/^1[3|4|5|7|8]\d{9}$/.test(parentPhone))) {
            alert("请输入有效的手机号码！");
            $(obj).attr("disabled",false);
            $(obj).attr("class","layui-btn layui-btn-normal");
            return false;
        }
        formData.append("parentPhone",parentPhone);
    }

    var incomeCoefficient = $("#incomeCoefficient").val(); //收益系数
    if(incomeCoefficient == "" || incomeCoefficient == undefined){
        alert("请完善提交信息");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }else {
        if(isNaN(incomeCoefficient)){
            alert("收益系数为数字");
            $(obj).attr("disabled",false);
            $(obj).attr("class","layui-btn layui-btn-normal");
            return false;
        }
    }

    var signingDate = $("#signingDate").val(); //签约日期
    if(signingDate == "" || signingDate == undefined){
        alert("请完善提交信息");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var validStartDate = $("#validStartDate").val(); //履约开始日期
    if(validStartDate == "" || validStartDate == undefined){
        alert("请完善提交信息");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var validEndDate = $("#validEndDate").val(); //履约结束日期
    if(validEndDate == "" || validEndDate == undefined){
        alert("请完善提交信息");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    if(validEndDate < validStartDate){
        alert("起始日期不能大于结束日期");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var operatorName = $("#operatorName").val(); //经办人
    if(operatorName == "" || operatorName ==undefined){
        alert("请完善提交信息");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var contractNo = $("#contractNo").val(); //合同号
    if(contractNo == "" || contractNo == undefined){
        alert("请完善提交信息");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }

    var file1 = $("#zm")[0].files[0]; //身份证照片
    var file2 = $("#fm")[0].files[0]; //身份证照片
    var file3 = $("#sc")[0].files[0]; //身份证照片
    if(file1 == undefined || file2 == undefined || file3 == undefined){
        alert("请上传三张身份证照片");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }

    var menuId = $("#menuId").val();
    formData.append("menuId",menuId);
    formData.append("type","add");
    formData.append("fphone",fphone);
    formData.append("provinceCode",provinceCode);
    formData.append("cityCode",cityCode);
    formData.append("countyCode",countyCode);
    formData.append("agentName",agentName);
    formData.append("identityCard",identityCard);

    formData.append("incomeCoefficient",incomeCoefficient);
    formData.append("signingDate",signingDate);
    formData.append("validStartDate",validStartDate);
    formData.append("validEndDate",validEndDate);
    formData.append("operatorName",operatorName);
    formData.append("contractNo",contractNo);
    var userId = $("#fUserId").val();
    formData.append("userId",userId);
    formData.append("agentLevel",agentLevel);

    formData.append("file1",file1);
    formData.append("file2",file2);
    formData.append("file3",file3);

    $.ajax({
        type: "post",
        url: "/agent/addAgent",
        data: formData,
        processData : false,
        contentType : false,
        dataType: "json",
        success: function (data) {
            if (data.code == 1 && data.code != undefined) {
                alert(data.message);
                $(obj).attr("disabled",false);
                $(obj).attr("class","layui-btn layui-btn-normal");
                layer.close(addAgentIndex);
                findAgentList();
            } else if (data == 9999 && data != undefined) {
                window.location.href = "/login_toLogin";
            } else if (data == 1111 && data != undefined) {
                alert("无权操作");
            } else if (data.code == 2 && data.code != undefined) {
                alert(data.message);
                $(obj).attr("disabled",false);
                $(obj).attr("class","layui-btn layui-btn-normal");
            }
        }
    });
}

//根据手机号码查询用户信息
function findUser() {
    var phone = $("#aPhone").val();
    if (!(/^1[3|4|5|7|8]\d{9}$/.test(phone))) {
        alert("请输入有效的手机号码！");
        return false;
    }
    var menuId = $("#menuId").val();
    var params = {
        "type": "query",
        "menuId": menuId,
        "phone": phone
    };

    $.ajax({
        type: "post",
        url: "/user/findUserByPhone",
        data: params,
        dataType: "json",
        success: function (data) {
            if (data.code == 1 && data.code != undefined) {
                $("#fPhone").val(data.user.phone);
                $("#fName").val(data.user.nickName);
                $("#fUserId").val(data.user.id);
                findAddres();
            } else if (data == 9999 && data != undefined) {
                window.location.href = "/login_toLogin";
            } else if (data == 1111 && data != undefined) {
                alert("无权操作");
            } else if (data.code == 2 && data.code != undefined) {
                alert("用户不存在");
            }
        }
    });
}

//根据代理身份不同查询省市区
function findAddres() {
    var menuId = $("#menuId").val();
    var params = {
        "type": "query",
        "menuId": menuId,
        "phone": phone
    };

    var menuId = $("#menuId").val();
    var params = {
        "type": "query",
        "menuId": menuId
    };
    $.ajax({
        type: "post",
        url: "/agent/findAllProvince",
        data: params,
        dataType: "json",
        success: function (data) {
            var html = "";
            if (data.code == 1 && data.code != undefined) {
                var hatProvinces = data.hatProvinces;
                for (var p in hatProvinces) {
                    html += '<option value="' + hatProvinces[p].provinceid + '">' + hatProvinces[p].province + '</option>'
                }
            } else if (data == 9999 && data != undefined) {
                window.location.href = "/login_toLogin";
            }
            $("#provinceCode").append(html);
            $("#cityCode").html("<option value=''>请选择市区</option>");
            $("#countyCode").html("<option value=''>请选择区县</option>");
        }
    });
}

function findCity(provinceId) {
    if (provinceId != 0 && provinceId != undefined) {
        var menuId = $("#menuId").val();
        var params = {
            "type": "query",
            "menuId": menuId,
            "provinceId": provinceId
        };
        $.ajax({
            type: "post",
            url: "/agent/findCityByProvince",
            data: params,
            dataType: "json",
            success: function (data) {
                var html = ' <option value="">请选择市区</option>';
                if (data.code == 1 && data.code != undefined) {
                    var hatCities = data.hatCities;
                    for (var p in hatCities) {
                        html += '<option value="' + hatCities[p].cityid + '">' + hatCities[p].city + '</option>'
                    }
                } else if (data == 9999 && data != undefined) {
                    window.location.href = "/login_toLogin";
                } else if (data == 1111 && data != undefined) {
                    alert("无权操作");
                }
                $("#cityCode").html(html);
            }
        });
    } else {
        $("#cityCode").html("<option value=''>请选择市区</option>");
        $("#countyCode").html("<option value=''>请选择区县</option>");
    }
}
function findArea(cityId) {
    if (cityId != 0 && cityId != undefined) {
        var menuId = $("#menuId").val();
        var params = {
            "type": "query",
            "menuId": menuId,
            "cityId": cityId
        };
        $.ajax({
            type: "post",
            url: "/agent/findAreaByCity",
            data: params,
            dataType: "json",
            success: function (data) {
                var html = ' <option value="">请选择区县</option>';
                if (data.code == 1 && data.code != undefined) {
                    var hatAreas = data.hatAreas;
                    for (var p in hatAreas) {
                        html += '<option value="' + hatAreas[p].areaid + '">' + hatAreas[p].area + '</option>'
                    }
                } else if (data == 9999 && data != undefined) {
                    window.location.href = "/login_toLogin";
                } else if (data == 1111 && data != undefined) {
                    alert("无权操作");
                }
                $("#countyCode").html(html);
            }
        });
    } else {
        $("#countyCode").html("<option value=''>请选择区县</option>");
    }
}
function isParent(v) {
    if(v == 1){
        $("#parentPhone").attr("disabled",true);
        $("#parentPhone").val("");
    }else if(v == 2){
        $("#parentPhone").attr("disabled",false);
    }
}
